from pydantic import BaseModel
from datetime import datetime
from typing import Optional, List

class ChapterContentBase(BaseModel):
    content: str
    raw_content: Optional[str] = None
    processed_content: Optional[str] = None

class ChapterContentCreate(ChapterContentBase):
    chapter_id: int

class ChapterContentResponse(ChapterContentBase):
    id: int
    created_at: datetime
    modified_at: datetime

    class Config:
        orm_mode = True

class ChapterBase(BaseModel):
    name: str
    order: int
    description: Optional[str] = None
    document_id: int
    parent_id: Optional[int] = None
    start_page: int
    end_page: int

class ChapterCreate(ChapterBase):
    content: Optional[str] = None  # 创建章节时可以同时提供内容

class ChapterResponse(ChapterBase):
    id: int
    created_at: datetime
    modified_at: datetime
    children: List['ChapterResponse'] = []
    content: Optional[ChapterContentResponse] = None  # 包含章节内容

    class Config:
        orm_mode = True 